import java.util.ArrayList;
import java.util.List;

public class NO4 {

    public static void main(String[] args) {
        int[] a=new int[]{1,3};
        int[] b=new int[]{2,4};
        System.out.println(Solution.findMedianSortedArrays(a,b));


    }
    static class Solution {
        public static double findMedianSortedArrays(int[] nums1, int[] nums2) {
            int m=0;
            int n=0;
            double result = 0;
            List<Integer> resList=new ArrayList<>();
            while (true){
                if(m<nums1.length&&n<nums2.length) {
                    if (nums1[m] < nums2[n]) {
                        resList.add(nums1[m]);
                        m++;
                    } else {
                        resList.add(nums2[n]);
                        n++;
                    }
                }else if(m<nums1.length){
                    resList.add(nums1[m]);
                    m++;
                }else if(n<nums2.length){
                    resList.add(nums2[n]);
                    n++;
                }else {
                    break;
                }
            }
            if((m+n)%2==0){
                int index=(m+n)/2;
                int res1=resList.get(index);
                int res2=resList.get(index-1);
                result=(double)(res1+res2)/2;
            }else{
                int index=(m+n)/2;
                result=resList.get(index);
            }

            return result;
        }
    }

}
